 <#include "../common/layout.html"/>
 <@layout title1="博客" title2="编辑博客">
<link rel="stylesheet" href="${basepath!}/static/kindeditor/themes/default/default.css" />
		<script charset="utf-8" src="${basepath!}/static/kindeditor/kindeditor-min.js"></script>
		<script charset="utf-8" src="${basepath!}/static/kindeditor/lang/zh_CN.js"></script>
		
		<script type="text/javascript">
			//KindEditor 初始化
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="bean.content"]', {
				 	uploadJson : '${basepath!}/admin/blog/editor_upload',
	                allowFileManager : true,
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : true,
					cssPath : ['${basepath!}/static/css/kindeditor_code.css'],
					//解决部分浏览器获取不到Kindeditor值的问题
					afterBlur: function(){this.sync();},
					items : [
						'fontname', 'fontsize', '|','code','baidumap','emoticons',"|", 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|','hr', 'image', 'link','|','preview','undo','redo']
				});
			});
			// prettyPrint();
			//保存文章
			
			function savebean(type){
				
				$("#blog_content input[name='bean.status']").val(type);
			//	document.getElementById("editor-content").value=KE.util.getData('editor-content');
				
				
				$("#blog_content").attr("action","${basepath!}/admin/blog/save");
				$("#blog_content").submit();
				
			}
			//取消编辑
			function cancel(){
				location.href = "${basepath!}/admin/blog/list";
			}
			
			//初始化下拉选择Select
			$(function(){
				initSelect();
			});
			
			//初始化标签
			$(function(){
				$(".bean_tag").each(function(){
					
					var bean_tag_val = $(this).val();
					$("input[name=tag_id]").each(function(){
						var tag_id = $(this).val();
						if(bean_tag_val==tag_id){
							$(this).prev().addClass("btn-primary");
							$(this).attr("checked","checked");
						}
					});
				
				});
			});
			
			//标签选择处理
			$(function(){
				$('.tag_name').click(function(){
					if($(this).next("input").attr("checked")=="checked"){
						$(this).removeClass("btn-primary");
						$(this).next("input").removeAttr("checked")
					}else{
						$(this).addClass("btn-primary");
						$(this).next("input").attr("checked","checked")
					}
				});
			});
			
		</script>
 
<div class="row-fluid">

<div class="well">
		<#if (bean.tags)??>
		<#list bean.tags as tag>
		    <input value="${(tag.id)!}" type="hidden" class="bean_tag">
		 </#list>
		 </#if>
	    <form id="blog_content" class="form-horizontal" method="post" >
	    	<input type="hidden" name="bean.id" value="${(bean.id)!}"/>
	    	<input type="hidden" name="bean.status" value="${(bean.status)!}"/>
		  <div class="control-group">
		    <label class="control-label"  for="inputTitle">标题</label>
		    <div class="controls">
		      <input value="${(bean.title)!}" type="text" name="bean.title" class="input-xlarge" id="inputTitle" placeholder="请输入标题"/>
		    </div>
		  </div>
		  <div class="control-group">
		    <label class="control-label" for="inputPassword">正文</label>
		    <div class="controls">
		      <textarea id="editor-content" name="bean.content" style="width:800px;height:700px;visibility:hidden;">${(bean.content)!}</textarea>
		    </div>
		  </div>
		 <div class="control-group">
		    <label class="control-label">标签</label>
		    <div class="controls" style=" line-height:30px;">
		    	
		    	<#list beans as x>
		    		<button class="tag_name btn btn-small " type="button">${(x.tag_name)!}</button>
		    		<input name="tag_id" type="checkbox" style="display:none;" value="${(x.id)!}"/>
		    	</#list>
				  <br/>
				  <span class="label label-important">输入新标签</span><input name="new_tag" type="text" class="input-small" placeholder="新标签"><span class="label">以英文逗号分隔多个标签</span>
		    </div>
		  </div>
		   <div class="control-group">
		    <label class="control-label">是否置顶</label>
		     <div class="controls" style=" line-height:30px;">
		   	<select name="bean.isTop" defValue="${(bean.isTop)!0}">
			  <option value="0">否</option>
			  <option value="1">是</option>
			</select>
			</div>
		  </div>
		   <div class="control-group">
		   <label class="control-label">博客类型</label>
		    <div class="controls" style=" line-height:30px;">
		    <select name="bean.blog_type" defValue="${(bean.blog_type)!0}">
		     <#list blogtypes as type>
			  <option value="${(type.id)!0}">${(type.type_name)!0}</option>
			  </#list>
			</select>
			</div>
			</div>
		<div class="btn-toolbar" style=" text-align:center; margin:0 auto;">
		    <button class="btn btn-primary" onclick="savebean(1)">发布</button>
		    <button class="btn btn-primary" onclick="savebean(0)">暂存</button>
		    <button type="button" onclick="cancel()" class="btn btn-danger">取消</button>
		</div>
	</form>
		
</div>

</div>
</@layout>